import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreExportService extends BaseService<any> {
  private readonly logger = new Logger(CoreExportService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * add
   * 对应 PHP: CoreExportService_core::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $export = $this->model->create($data);         return $export->id;     }      /**      * 报表导出更新      * @param int $export_id      * @param array $data...
const export = this.model.create(data);
        return export.id;
    }

    /**
     * 报表导出更新
     * @param int export_id
     * @param data
     * @return true
     */
    async edit(int export_id, data)
    {
        const where = [id: export_id];
        this.model.where(where).update(data);
        return true;
    }

    /**
     * 获取导出数据类型列表
     * @return */
    async getExportDataType()
    {
        const type_ = event("ExportDataType"];
        const type_list = [];
        const data = [);
        foreach (type_as v)
        {
            const type_list = !type_list) ? v : any[]_merge(type_list, v);
  }

  /**
   * edit
   * 对应 PHP: CoreExportService_core::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(export_id: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $where = ['id' => $export_id];         $this->model->where($where)->update($data);         return true;     }      /**      * 获取导出数据类型列表      * @retur...
const where = [id: export_id];
        this.model.where(where).update(data);
        return true;
    }

    /**
     * 获取导出数据类型列表
     * @return */
    async getExportDataType()
    {
        const type_ = event("ExportDataType"];
        const type_list = [];
        const data = [);
        foreach (type_as v)
        {
            const type_list = !type_list) ? v : any[]_merge(type_list, v);
  }

  /**
   * getExportDataType
   * 对应 PHP: CoreExportService_core::getExportDataType()
   * 逻辑类型: undefined - undefined
   */
  async getExportDataType() {
    // 基于PHP真实逻辑: getExportDataType
    // PHP原文: $type_array = event("ExportDataType");         $type_list = [];         $data = [];         foreach ($type_array as $v)         {             $type_li...
const type_ = event("ExportDataType"];
        const type_list = [];
        const data = [);
        foreach (type_as v)
        {
            const type_list = !type_list) ? v : any[]_merge(type_list, v);
  }

  /**
   * getExportDataColumn
   * 对应 PHP: CoreExportService_core::getExportDataColumn()
   * 逻辑类型: undefined - undefined
   */
  async getExportDataColumn(site_id: any[], type: any[], where: any[]) {
    // 基于PHP真实逻辑: getExportDataColumn
    // PHP原文: $param['site_id'] = $site_id;         $param['where'] = $where;         $type_array = event("ExportDataType", $param);         $type_list = [];       ...
param.site_id = site_id;
        param.where = where;
        const type_ = event("ExportDataType", param];
        const type_list = [);
        foreach (type_as v)
        {
            const type_list = !type_list) ? v : any[]_merge(type_list, v);
  }

  /**
   * getExportData
   * 对应 PHP: CoreExportService_core::getExportData()
   * 逻辑类型: undefined - undefined
   */
  async getExportData(site_id: any[], type: any[], where: any[], page: any[]) {
    // 基于PHP真实逻辑: getExportData
    // PHP原文: $param['site_id'] = $site_id;         $param['type'] = $type;         $param['where'] = $where;         $param['page'] = $page;         $data_array = ...
param.site_id = site_id;
        param.type = type;
        param.where = where;
        param.page = page;
        const data_ = event("ExportData", param];
        const data_list = [);
        foreach (data_as v)
        {
            const data_list = !data_list) ? v : any[]_merge(data_list, v);
  }

  /**
   * export
   * 对应 PHP: CoreExportService_core::export()
   * 逻辑类型: undefined - undefined
   */
  async export(site_id: any[], data_key: any[], data_column: any[], data: any[]) {
    // 基于PHP真实逻辑: export
    // PHP原文: // 假设你有一个订单数组，每个订单是一个关联数组 //        $data_column = [ //            'id' =>[ //                'name' => '主键', //            ], //            'customer...
// 假设你有一个订单数组，每个订单是一个关联数组
//        data_column = [
//            id:[
//                name: '主键',
//            ],
//            customer_name: [
//                name: '客户名称'
//            ],
//            order_date: [
//                name: '订单数据'
//            ],
//            total_amount: [
//                name: '订单金额'
//            ],
//        ];
//        data = [
//            [
//                id: 1,
//                customer_name: 'John Doe',
//                order_date: '2023-10-23',
//                total_amount: 100.00,
//                // ... 其他订单字段
//            ],
//            [
//                id: 2,
//                customer_name: 'Jane Smith',
//                order_date: '2023-10-24',
//                total_amount: 150.00,
//                // ... 其他订单字段
//            ],
//            // ... 其他订单数据
//        ];


        // 创建一个新的Spreadsheet对象
        const spreadsheet = this.spreadsheetService;
        const sheet = spreadsheet.getActiveSheet(];

        //组装excel列标识
        const i = 0;
        foreach (data_column as k => v)
        {
            data_column[k].excel_column_name = this.getExcelColumnName(i);
            i ++;
  }

  /**
   * deleteExportFile
   * 对应 PHP: CoreExportService_core::deleteExportFile()
   * 逻辑类型: undefined - undefined
   */
  async deleteExportFile(file_path: any) {
    // 基于PHP真实逻辑: deleteExportFile
    // PHP原文: $file = public_path() . $file_path;         if (file_exists($file)) {             if (unlink($file)) {                 Log::write('报表文件删除成功');        ...
const file = public_path() . file_path;
        if (file_exists(file)) {
            if (unlink(file)) {
                Log.write('报表文件删除成功'];
            } } } else {
                Log.write('报表文件删除失败！文件路径：'.file_path);
            }
  }

  /**
   * getExcelColumnName
   * 对应 PHP: CoreExportService_core::getExcelColumnName()
   * 逻辑类型: undefined - undefined
   */
  async getExcelColumnName(index: any) {
    // 基于PHP真实逻辑: getExcelColumnName
    // PHP原文: $numeric = $index + 1; // Excel 列索引从 1 开始         $stringValue = '';         $value = $numeric;          while ($value > 0) {             $stringValue...
const numeric = index + 1; // Excel 列索引从 1 开始
        const stringValue = '';
        const value = numeric;

        while (value > 0) {
            const stringValue = chr((value - 1) % 26 + ord('A')) . stringValue;
            const value = intval((value - 1) / 26];
  }
}
